/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.kason.splicing;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.util.CharsetUtil;

/**
 * @author 卢清波
 * @date 2021/2/1 17:48
 */
public class SplicingClient
{
    public static void main(String[] args) throws InterruptedException
    {
        NioEventLoopGroup en = new NioEventLoopGroup();
        try
        {
            Bootstrap cs = new Bootstrap();
            cs.group(en).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>()
            {
                @Override
                protected void initChannel(SocketChannel ch) throws Exception
                {
                    ChannelPipeline pipeline = ch.pipeline();
                    pipeline.addLast(new DelimiterBasedFrameDecoder(1024, Unpooled.copiedBuffer("_", CharsetUtil.UTF_8)));
                    pipeline.addLast(new SplicingClientHandler());
                }
            });
            ChannelFuture channelFuture = cs.connect("localhost", 9000).sync();

            ChannelFuture sync = channelFuture.channel().closeFuture().sync();
        }
        catch (Exception ex)
        {
            throw ex;
        }finally
        {
            en.shutdownGracefully();
        }




    }
}
